﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AutoBuy.aspx.cs" Inherits="WebTraderLite.Pages.AutoBuy" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ObjectDataSource ID="autobuyStockODS" runat="server" 
        SelectMethod="getStockInfo" TypeName="WebTraderLiteCL.stockDataQuery">
        <SelectParameters>
            <asp:ControlParameter ControlID="tbStockSym" Name="symbol" PropertyName="Text" 
                Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource> 
       
    <asp:MultiView ID="MultiViewautobuyStock" runat="server" ActiveViewIndex="0">

     <asp:View ID="viewautobuyStock" runat="server">
            <div>
                <table>
                    <tr>
                        <td>Search for stock to autobuy:</td>
                        <td><asp:TextBox ID="tbStockSym" runat="server" 
                                ontextchanged="tbStockSym_TextChanged" AutoPostBack="True"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td><asp:PlaceHolder ID="phFailSearch" runat="server"></asp:PlaceHolder></td>
                    </tr>
                </table>
        
            </div>
    
            <span class="failureNotification">
                <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
            </span>
            <asp:ValidationSummary ID="autobuyStockValidationSummary" runat="server" CssClass="failureNotification" 
                    ValidationGroup="autobuyStockValidationGroup"/>
    
            <br />
            <div>
                <asp:FormView ID="fvautobuyStock" runat="server" DataSourceID="autobuyStockODS">
                    <ItemTemplate>
                        <table frame="void">
                            <tr>
                                <td style="font-weight:bold">Stock:</td>
                                <td> <%# Eval("Symbol") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Company:</td>
                                <td> <%# Eval("CompanyName") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Current Price:</td>
                                <td> <%# Eval("Price", "{0:C}") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold; width:100px">Number of Shares to Buy:</td>
                                <td><asp:TextBox ID="tbNumShares" runat="server"></asp:TextBox></td>
                                <asp:RequiredFieldValidator ID="numSharesRequired" runat="server" ControlToValidate="tbNumShares"
                                    CssClass="failureNotification" ErrorMessage="Enter number of shares to autobuy." 
                                    ValidationGroup="autobuyStockValidationGroup" Display="None"></asp:RequiredFieldValidator>

                                <asp:CompareValidator ID="numSharesGreaterThanZero" runat="server" ControlToValidate="tbNumShares"
                                    ValidationGroup="autobuyStockValidationGroup" Operator="GreaterThan" ValueToCompare="0"
                                    Type="Integer" ErrorMessage="Number of Shares to autobuy must be &gt; 0" CssClass="failureNotification" Display="None"></asp:CompareValidator>
                                <td> if Price</td>
                                <td> 
                                <asp:DropDownList ID="trendList" runat="server" AppendDataBoundItems="False">
                                    <asp:ListItem Text="Less than"></asp:ListItem>
                                    <asp:ListItem Text="Greater than"></asp:ListItem>
                                </asp:DropDownList>
                                </td>

                                <td><asp:TextBox ID="tbTriggerPrice" runat="server"></asp:TextBox></td>
                                <asp:RequiredFieldValidator ID="requiredTriggerPrice" runat="server" ControlToValidate="tbTriggerPrice"
                                    CssClass="failureNotification" ErrorMessage="Enter price to trigger an autobuy." 
                                    ValidationGroup="autobuyStockValidationGroup" Display="None"></asp:RequiredFieldValidator>

                                <asp:CompareValidator ID="triggerPriceCompare" runat="server" ControlToValidate="tbTriggerPrice"
                                    ValidationGroup="autobuyStockValidationGroup" Operator="GreaterThan" ValueToCompare="0"
                                    Type="Integer" ErrorMessage="Price of autobuy must be &gt; 0" CssClass="failureNotification" Display="None"></asp:CompareValidator>
                            
                            </tr>
                            
                            
                            <tr>
                                <td colspan="2" style="text-align:right"> 
                                <asp:Button ID="btnautobuyStock" runat="server" Width="60%" Text="Schedule Buy" OnClick="showConfirmautobuy" CausesValidation="true" ValidationGroup="autobuyStockValidationGroup"/>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>            
                </asp:FormView>
                
            </div>

       </asp:View>
       
       <asp:View ID="viewConfirmautobuy" runat="server">
       <div style="margin-left:15px">
        <h2>Order Summary</h2>
       </div>
       
           <asp:PlaceHolder ID="phlconfirm" runat="server"></asp:PlaceHolder>
       
       <br />

        <div style="margin-left:auto; margin-right:auto">
                <asp:FormView ID="fvConfrimautobuy" runat="server" DataSourceID="autobuyStockODS" 
                    Width="223px">
                    <ItemTemplate>
                        <table frame="void">
                            <tr>
                                <td style="font-weight:bold">Stock:</td>
                                <td align="right"> <asp:Label ID="lblStockSym" runat="server" Text='<%# Eval("Symbol") %>'></asp:Label></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Company:</td>
                                <td align="right"> <%# Eval("CompanyName") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Current Price:</td>
                                <td align="right"> <%# Eval("Price", "{0:C}") %></td>
                            </tr>
                            
                            <tr>
                                <td style="font-weight:bold">Buy Stock if Price </td>
                                <td align="right"> <asp:Label ID="lblTrend" runat="server"></asp:Label></td>  
                                <td align="right"> <asp:Label ID="lblTriggerPrice" runat="server"></asp:Label></td>                                                     
                            
                            </tr>W
                            
                            <tr>
                                <td style="font-weight:bold">Number of Shares:</td>
                                <td align="right"><asp:Label ID="lblNumShares" runat="server"></asp:Label></td>                            
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Total Price:</td>
                                <td align="right"><asp:Label ID="lblTotPrice" runat="server"></asp:Label></td>
                            </tr>
                            <tr>
                                <td colspan="2" style="text-align:right"> 
                                <asp:Button ID="btnConfrimautobuy" runat="server" Width="65%" Text="Confirm Purchase" OnClick="processautobuy" />
                                </td>                               
                            </tr>
                            
                            <tr>
                                <td colspan="2" style="text-align:right"> 
                                <asp:Button ID="btnCancelautobuy" runat="server" Width="65%" Text="Cancel" OnClick="cancelautobuy"/>
                                </td>                               
                            </tr>
                        </table>
                    </ItemTemplate>            
                </asp:FormView>
            </div>
       
       </asp:View>    
</asp:MultiView>
</asp:Content>
